local sk__diaodu = fk.CreateSkill {

  name = "sk__diaodu",

  tags = {},

}



sk__diaodu:addEffect(fk.EventPhaseStart, {
  name = "sk__diaodu",
  anim_type = "control",
  can_trigger = function(self, event, target, player, data)
    return target == player and player:hasSkill(sk__diaodu.name) and player.phase == Player.Start
  end,
  on_cost = function(self, event, target, player, data)
    local _, dat = player.room:askForUseActiveSkill(player, "sk__diaodu_active", "#sk__diaodu-invoke", true, nil, false)
    if dat then
      event:setCostData(self, dat)
      return true
    end
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    local target1, target2 = room:getPlayerById(event:getCostData(self).targets[1]),
        room:getPlayerById(event:getCostData(self).targets[2])
    local n = 0
    if event:getCostData(self).interaction == "sk__diaodu_hand" then
      n = math.abs(target1:getHandcardNum() - target2:getHandcardNum())
      room:swapAllCards(player, {target1, target2}, sk__diaodu.name,"h")
    else
      local cards1 = table.clone(target1:getCardIds("e"))
      local cards2 = table.clone(target2:getCardIds("e"))
      n = math.abs(#cards1 - #cards2)
      room:swapCards(player, {{target1, cards1}, {target2, cards2}}, sk__diaodu.name, Card.PlayerEquip)
    end
    if n > 0 and not player.dead then
      room:askForDiscard(player, n, n, true, sk__diaodu.name, false)
    end
  end,
})

return sk__diaodu
